package model;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.util.Properties;

public class UID_Generator {
    private static final int a = 9999991;
    private static final int b = 11451403;
    private static int c = 0;

    public static String getUid(String prefix) {

        if(c==0){
            Properties prop = new Properties();
            try {
                File f = new File("UID_Number.txt");
                FileInputStream in = new FileInputStream(f);
                prop.load(in);
                c = Integer.parseInt(prop.getProperty("UID"));
                in.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        String id = String.valueOf(10000000+((long)c*b)%a);
        ++c;

        try {
            File f = new File("UID_Number.txt");
            FileWriter out = new FileWriter(f);
            out.write("UID=" + c);
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return prefix + id.substring(1);
    }

    public static void main(String[] args) {
        for(int i = 0; i <100; i++){
            System.out.println(getUid("?"));
        }

    }

}
